<?php 
	jimport('joomla.application.component.controller');
	//require 'components/com_kinh_doanh/tables/kinh_doanh.php';

	
	class sale_tsc_che_bienControllersu_luoc_che_bien extends JController
	{
        //cap naht stt
        function cap_nhat()
        {
            $con = $_SESSION['config'];
            $id_wh = $con->id_warehouse; 
            $model = $this->getModel("su_luoc_che_bien");
            
            $data = $model->ds_sp_bill($_POST['bill']);
            $db = &JFactory::getDBO();
             $sql = "UPDATE #__erp_sale SET
                                status =2
                                WHERE 
                                id ='".$_POST['bill']."'";
                                $db->setQuery($sql);
                                $db->query(); 
            foreach($data as $row)
            {
                if($_POST['id'.$row->id_od]==2)
                {
                    $sql = "UPDATE #__erp_sale_order SET
                                status = 2
                                WHERE 
                                id ='".$row->id_od."'";
                                $db->setQuery($sql);
                                $db->query();
                    $model->cap_nhat_lai_so_luong($row->id_pro,$id_wh,$row->number);
                }
                if($_POST['id'.$row->id_od]==3)
                {
                    
                    $sql = "UPDATE #__erp_sale_order SET
                                status = 3
                                WHERE 
                                id ='".$row->id_od."'";
                                $db->setQuery($sql);
                                $db->query();
                }
            }
            $this->setRedirect("index.php?option=com_sale_tsc_che_bien","Thanh Cong");
            return;
        }
        //neu khong co task nao phu hop thi mac se chay function nay
		function display()
		{
			JRequest::setVar('view','su_luoc_che_bien'); // goi view dang nhap
			parent::display();	 // hien thi
		}   
    }
?>